package com.jml.内存溢出.controller;


import com.jml.内存溢出.entity.User;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemoryController {

	private List<User> userList = new ArrayList<>();
	private List<Class<?>> classList = new ArrayList<>();
	/*
	* 设置jvm参数 -Xmx32m -Xms32m
	* */
	//堆内存溢出
	@RequestMapping("heapOutOfMemory")
	public String heapOutOfMemory(){
		int i=0;
		while(true){
			userList.add(new User(i++,"user"+i));
		}
	}
	/*
	 * 设置jvm参数 -XX:MetaspaceSize=32m
	 * */
	//非堆内存溢出metaspace
	@RequestMapping("noHeapOutOfMemory")
	public String noHeapOutOfMemory(){
		int i=0;
		while(true){
			classList.addAll(Metaspace.createClasses());
		}
	}

}
